/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import Entity.CTPhieuNhapSach;
import Util.DatabaseHandle;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Dark_Knight
 */
public class CTPhieuNhapSachImpl implements CTPhieuNhapSachDAO {

    public boolean add(CTPhieuNhapSach data) {
        String sql = "{call sp_CT_PHIEUNHAPSACH_add(?,?,?,?)}";
        DatabaseHandle db = new DatabaseHandle(sql, true);
        try {
            db.setParameter(1, data.getMaPhieuNhapSach());
            db.setParameter(2, data.getMaSach());
            db.setParameter(3, data.getSoLuongNhap());
            db.setParameter(4, data.getDonGiaNhap());
            db.executeStorePro();
            db.closed();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(CTPhieuNhapSachImpl.class.getName()).log(Level.SEVERE, null, ex);
            db.closed();
            return false;
        }
    }

    public boolean delete(int MaPhieuNhapSach, int MaSach) {
         String sql = "{call sp_CT_PHIEUNHAPSACH_add(?,?,?,?)}";
        DatabaseHandle db = new DatabaseHandle(sql, true);
        try {
            db.setParameter(1, MaPhieuNhapSach);
            db.setParameter(2, MaSach);
            db.executeStorePro();
            db.closed();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(CTPhieuNhapSachImpl.class.getName()).log(Level.SEVERE, null, ex);
            db.closed();
            return false;
        }
    }

    public boolean edit(CTPhieuNhapSach data) {
        String sql = "{call sp_CT_PHIEUNHAPSACH_add(?,?,?,?)}";
        DatabaseHandle db = new DatabaseHandle(sql, true);
        try {
            db.setParameter(1, data.getMaPhieuNhapSach());
            db.setParameter(2, data.getMaSach());
            db.setParameter(3, data.getSoLuongNhap());
            db.setParameter(4, data.getDonGiaNhap());
            db.executeStorePro();
            db.closed();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(CTPhieuNhapSachImpl.class.getName()).log(Level.SEVERE, null, ex);
            db.closed();
            return false;
        }
    }
    
}
